package com.ruoyi.models.controller.cost;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cost.domain.CostCustomerInfo;
import com.ruoyi.cost.service.ICostCustomerInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

/**
 * 客户账户Controller
 * 
 * @author zomcx
 * @date 2025-06-12
 */
@RestController
@RequestMapping("/cost/customerInfo")
@Tag(name = "【客户账户】管理")
public class CostCustomerInfoController extends BaseController
{
    @Autowired
    private ICostCustomerInfoService costCustomerInfoService;

    /**
     * 查询客户账户列表
     */
    @Operation(summary = "查询客户账户列表")
    @PreAuthorize("@ss.hasPermi('cost:customerInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(CostCustomerInfo costCustomerInfo)
    {
        startPage();
        List<CostCustomerInfo> list = costCustomerInfoService.selectCostCustomerInfoList(costCustomerInfo);
        return getDataTable(list);
    }

    /**
     * 导出客户账户列表
     */
    @Operation(summary = "导出客户账户列表")
    @PreAuthorize("@ss.hasPermi('cost:customerInfo:export')")
    @Log(title = "客户账户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CostCustomerInfo costCustomerInfo)
    {
        List<CostCustomerInfo> list = costCustomerInfoService.selectCostCustomerInfoList(costCustomerInfo);
        ExcelUtil<CostCustomerInfo> util = new ExcelUtil<CostCustomerInfo>(CostCustomerInfo.class);
        util.exportExcel(response, list, "客户账户数据");
    }

    /**
     * 获取客户账户详细信息
     */
    @Operation(summary = "获取客户账户详细信息")
    @PreAuthorize("@ss.hasPermi('cost:customerInfo:query')")
    @GetMapping(value = "/{costCustomerId}")
    public AjaxResult getInfo(@PathVariable("costCustomerId") Long costCustomerId)
    {
        return success(costCustomerInfoService.selectCostCustomerInfoByCostCustomerId(costCustomerId));
    }

    /**
     * 新增客户账户
     */
    @Operation(summary = "新增客户账户")
    @PreAuthorize("@ss.hasPermi('cost:customerInfo:add')")
    @Log(title = "客户账户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CostCustomerInfo costCustomerInfo)
    {
        return toAjax(costCustomerInfoService.insertCostCustomerInfo(costCustomerInfo));
    }

    /**
     * 修改客户账户
     */
    @Operation(summary = "修改客户账户")
    @PreAuthorize("@ss.hasPermi('cost:customerInfo:edit')")
    @Log(title = "客户账户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CostCustomerInfo costCustomerInfo)
    {
        return toAjax(costCustomerInfoService.updateCostCustomerInfo(costCustomerInfo));
    }

    /**
     * 删除客户账户
     */
    @Operation(summary = "删除客户账户")
    @PreAuthorize("@ss.hasPermi('cost:customerInfo:remove')")
    @Log(title = "客户账户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{costCustomerIds}")
    public AjaxResult remove(@PathVariable( name = "costCustomerIds" ) Long[] costCustomerIds) 
    {
        return toAjax(costCustomerInfoService.deleteCostCustomerInfoByCostCustomerIds(costCustomerIds));
    }
}
